'use strict';
//
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	//获取数据库对象
	const db = uniCloud.database();
	//获取表的对象
	const tb = db.collection("category");
	//根据类型进行操作
	switch (event.type) {
		//查找所有分类
		case 'category': {
			let res = await tb.get();
			return res;
		};
		//联表查找所有该分类的工作
		case "showCategoryJob": {
			let {category_id}=event;
			//查找
			let data=await tb.aggregate().match({
				_id:category_id
			}).lookup({
				from:'job',
				localField:'_id',
				foreignField:'category_id',
				as:'jobsList'
			}).end()
			return {status:200,data:data}
		};
		//删除
		case "deleteById": {
			let _id = event.id;
			let res = await tb.doc(_id).remove()
			return res;
		};
		

	}
};
